<?php
/**
 * Manage installations of lets manager on piwam project
 *
 * @package    letsManager
 * @subpackage letsInstall
 * @author     Jerome Fouilloy
 * @version    SVN: $Rev$
 */
class letsInstallActions extends sfActions
{
  /**
   * Executes install action
   *
   * @param sfRequest $request A request object
   */
  public function executeInstall(sfWebRequest $request)
  {

    $assoId = $this->getUser()->getAssociationId();
    $template = MailTemplateTable::templateExist($assoId,LetsManagerEmails::KEY_EXCHANGE_PENDING);
    //lets manager already installed
    if($template != null)
    {
      $this->getUser()->setFlash('notice','Installation du gestionnaire de SEL déjà faite');
      $this->redirect('@lets_home_member');
    }
    Doctrine::loadData(sfConfig::get('sf_plugins_dir').'/pwLetsManagerPlugin/data/fixtures/configuration.yml',true);

    $config2 = sfConfig::get('sf_plugins_dir').'/pwLetsManagerPlugin/data/fixtures/configuration2.yml';
    DbTools::loadYmlFileForAssociation($config2,$assoId);

    // update group admin rights
   // LetsXmlDataImporter::importMembers($this,sfConfig::get('sf_plugins_dir').'/pwLetsManagerPlugin/data/adherents.xml',$this->getuser()->getAssociationId());
   // LetsXmlDataImporter::importOffres(sfConfig::get('sf_plugins_dir').'/pwLetsManagerPlugin/data/offres.xml');
   // LetsXmlDataImporter::importDemandes(sfConfig::get('sf_plugins_dir').'/pwLetsManagerPlugin/data/demandes.xml');
     /*  $members = LetsMemberTable::getEnabledForAssociation(1,true);
     foreach($members as $member)
     {
       if($member->getId() > 1)
       {
         $prenom = $member->getLastname();
         $nom = $member->getFirstname();
         $member->setLastname($nom);
         $member->setFirstname($prenom);
         $member->save();
       }
     }*/
    $this->setTemplate('endInstall');
  }
  
  public function executeErrorConfig(sfWebRequest $request)
  {
    $this->module = $request->getParameter('moduleSource','Non spécifié');
    $this->action = $request->getParameter('actionSource','Non spécifié');
    $this->variable = $request->getParameter('variable','Non spécifié');
    $this->problem = $request->getParameter('problem','Non spécifié');
  }
}
